package cn.hl.sfzy.controller;

import cn.hl.sfzy.entity.Heartknowledge;
import cn.hl.sfzy.service.HeartknowledgeService;
import cn.hl.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/heartknowledge")
public class HeartknowledgeController {
    @Autowired
    private HeartknowledgeService heartknowledgeService;
    @GetMapping("/find")
    public Result find(
        @RequestParam(required = false,defaultValue = "1") int pageNum,
        @RequestParam(required = false,defaultValue = "5") int pageSize,
    Heartknowledge heartknowledge
            ){
            PageInfo<Heartknowledge> bypage =heartknowledgeService.findBypage(pageNum, pageSize,heartknowledge);
            Result result=Result.success(bypage);
        return result;
    }
    @PostMapping("/add")
    public Result add(@RequestBody Heartknowledge heartknowledge){
        System.out.println(heartknowledge.toString());
        System.out.println(heartknowledge);
        int i = heartknowledgeService.add(heartknowledge);
        return Result.success(heartknowledge);
    }
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id){
        System.out.println(id);
heartknowledgeService.deleteById(id);
        return Result.success("删除成功");
    }
    @PutMapping("/update")
    public Result update(@RequestBody Heartknowledge heartknowledge){
        int update = heartknowledgeService.update(heartknowledge);
        return Result.success(heartknowledge);
    }
}
